package com.yaofeng.mybatis.interceptor;

import com.yaofeng.mybatis.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * token在有效时间内刷新，返回刷新后的token放在header中key值Authorization
 * 因为用了XssFilter 过滤器 返回的response要在preHandle前设置有效
 * afterCompletion中设置header无效
 * Created by yaofeng on 2019/9/5.
 */
@Slf4j
public class RefreshTokenInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("=================preHandle====================");
        Object   object   =  request.getAttribute(Constants.REFRESH_TOKEN);
        String refeshToken =object==null?"":object.toString();
        log.info("refreshToken:{}",refeshToken);
        response.setHeader("refresh_token",refeshToken);
        return true;
    }


}
